package com;

import java.util.ArrayList;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class MyClass {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ArrayList<String> arr = new ArrayList<String>();
		arr.add("x27*UMu");
		arr.add("22MMMaa");
		arr.add("MMMaaaa");
		for(String str : arr){
			System.out.println(validatePassword(str));
			
		}

	}
	
	public static boolean validatePassword(String password){
		boolean status = false;
		
		if(password.length() >= 7 && password.length() <= 20){
			if(Pattern.compile(".*?[A-Z]{1}.*").matcher(password).matches() && 
					Pattern.compile(".*?[a-z]{1}.*").matcher(password).matches() &&
					(Pattern.compile(".*?[0-9]{1}.*").matcher(password).matches() || 
							Pattern.compile(".*?[!@#$%*]{1}.*").matcher(password).matches()))
				status = true;
		}
		
		return status;
	}
	
	public static String generatePassword(){
		 String allowedCharacters1 = "ABCDEFGHIJKLMOPQRSTUVWXYZ";
		 String allowedCharacters2 = "abcdefghijklmopqrstuvwxyz";
		 String allowedCharacters3 = "0123456789";
		 String allowedCharacters4 = "!@#$%*";
		 String allowedCharacters5 = "ABCDEFfghijklGHIJKLMOPQRS!@#$*TUVWXYZabcdemopqrstuvwxyz0123456789";
		 
		 Random r = new Random();
		 StringBuilder strbld = null;
		 strbld=new StringBuilder();
		 strbld.append (allowedCharacters5.charAt(r.nextInt(allowedCharacters5.length())));
		 strbld.append (allowedCharacters3.charAt(r.nextInt(allowedCharacters3.length())));
		 strbld.append (allowedCharacters5.charAt(r.nextInt(allowedCharacters5.length())));
		 strbld.append (allowedCharacters4.charAt(r.nextInt(allowedCharacters4.length())));
		 strbld.append (allowedCharacters5.charAt(r.nextInt(allowedCharacters5.length())));
		 strbld.append (allowedCharacters1.charAt(r.nextInt(allowedCharacters1.length())));
		 strbld.append (allowedCharacters2.charAt(r.nextInt(allowedCharacters2.length())));
	     System.out.println("Random Password :" + " "+ strbld.toString());
		 
	     return strbld.toString();
	}
	


}

